#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for server.jar
 
PIDFILE=/var/run/java.pid
SERVER=./server.jar

ARGS="
-Dcom.sun.management.jmxremote.port=1090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Xms1024m
-Xmx1024m 
-Xmn384m 
-Xss256k 
-XX:PermSize=512M
-XX:MaxPermSize=512m
-XX:+DisableExplicitGC
-XX:+UseConcMarkSweepGC
-XX:+CMSParallelRemarkEnabled
-XX:+UseCMSCompactAtFullCollection
-XX:LargePageSizeInBytes=128m
-XX:+UseFastAccessorMethods
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=50
"

start()
{
	if test -e $SERVER
	then
		echo -e "Starting $SERVER"
	#               if nohup java $ARGS -jar $SERVER> /dev/null 2>&1 &
			if nohup java $ARGS -jar $SERVER
		then
			echo $! > $PIDFILE
			echo -e "server start OK"
		else
			echo -e "server start failed"
		fi
	else
		echo -e "Couldn't find server.jar"
	fi
}
 
stop()
{
         if test -e $PIDFILE
         then
                   echo -e "Stopping server"
                   if kill `cat $PIDFILE`
                   then
                            echo -e "server stop OK"
                   else
	                    echo -e "server stop faild"
                   fi
         else
                   echo -e "No server running"
         fi
}
 
restart()
{
    echo -e "Restarting server"
    stop
    start
}

case $1 in
         start)
                start
        ;;
         stop)
        	stop
        ;;
         restart)
        	restart
        ;;
         *)
        	echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
        exit 1
        ;;
esac
exit 0
